<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>订单管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="icon" href="/images/favicon.ico">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form id="form1" class="layui-form layui-form-pane" method="post" target="_blank" action="/order/export">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">关键字</label>
                            <div class="layui-input-inline">
                                <label><input id="keyword" type="text" name="keyword" autocomplete="off" class="layui-input"></label>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button id="searchBtn" type="button" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn">
                                <i class="layui-icon"></i> 搜 索
                            </button>
                            <button id="exportBtn" type="button" class="layui-btn layui-btn-primary" lay-submit>
                                <i class="layui-icon layui-icon-export"></i> 导 出
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>


        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>


        <script type="text/html" id="currentTableBar">
            {{#  if(d.status == 1 ){ }}
            <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="start"><i class="layui-icon layui-icon-release"></i>发货</a>
            {{#  }  }}
            <a class="layui-btn layui-btn-normal  layui-btn-xs" id="show" lay-event="show"><i class="layui-icon layui-icon-search"></i>详情</a>
        </script>

    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/lay-config.js" charset="utf-8"></script>
<script th:inline="none">
    layui.use(['form', 'table', 'layer', 'upload', 'common'], function () {
        let $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            layer = layui.layer;

        // 导出按钮绑定事件
        $("#exportBtn").on("click", function() {
            $("#form1").submit();
        });

        // 搜索按钮绑定事件
        let search = $("#searchBtn").on("click", function () {
            // table表格渲染数据
            table.render({
                elem: '#currentTableId',
                url: '/order/list', // 发送请求的地址
                where: {
                    keyword: $("#keyword").val()
                },
                cols: [[
                    {type: 'checkbox', field: 'left'},
                    {field: 'code', title: '订单号', width: 238},
                    {field: 'mcode', title: '会员码', width: 291},
                    {field: 'createtime', title: '下单时间', width: 202},
                    {field: 'status', title: '状态', sort: true, width: 90, templet: function (data) {
                            let btn = "";
                            switch (data.status){
                                case 0:
                                    btn = '<span style="font-size:16px;color:red">待支付</span>';
                                    break;
                                case 1 :
                                    btn = '<span style="font-size:16px;color:#1cbb1f">已支付</span>';
                                    break;
                                case 2 :
                                    btn = '<span style="font-size:16px;color:#0a50e6">已发货</span>';
                                    break;
                                case 3 :
                                    btn = '<span style="font-size:16px;color:#696f6b">已完成</span>';
                                    break;
                            }
                            return btn;
                        }
                    },
                    {field: 'price', title: '金额', width: 82, style: 'color: darkcyan'},
                    {field: 'remark', title: '支付方式', width: 92, style: 'color: yellow'},
                    {title: '操作', toolbar: '#currentTableBar', align: "right"}
                ]],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 10,
                page: true,
                skin: 'line'
            }); //end table.render
        }); //end $("#searchBtn")
        search.click();
        // 提示信息
        let infoMsg = function (info) {
            layer.msg(info, {
                icon: 1,
                time: 1200
            });
        }
        let infoErrorMsg = function (info) {
            layer.msg(info, {
                icon: 5,
                time: 1200
            });
        }

        // 表格操作工具条时间
        table.on('tool(currentTableFilter)', function (obj) {
            if (obj.event === 'start') { // 点的是编辑
                $.post("/order/start/" + obj.data.id, function () {
                    infoMsg("已成功发货！");
                    search();
                });
            } //end if


        }); //end tool(currentTableFilter)



    }); //end layui.use
</script>

</body>
</html>